//
//  BoundHomeViewModel.swift
//  EasePods
//
//  Created by 易先生 on 2024/4/8.
//

import UIKit
import Differentiator
import RxCocoa
import RxSwift

public enum HomeActionItem {
 
    case headItem(ViewModel: HomeHeadCellModel)
    case equalizerItem(viewModel: HomeEqualizerCellViewModel)
    case spatialAudioSectionItem
    case spatialAudioItem(viewModel: HomeSpatialAudioCellModel)
    case settingItem(viewModel: HomeSettingCellModel)
}

open class HomeViewModel: ViewModel, ViewModelType {
    
    public struct Input {
        public let viewWillAppear: ControlEvent<Bool>
        public init(viewWillAppear: ControlEvent<Bool>) {
            self.viewWillAppear = viewWillAppear
        }
    }

    public struct Output {
        public let items: Observable<[HomeActionItem]>
    }
    
    public func transform(input: Input) -> Output {
        
        let dataSource = Observable.of(Observable.just(()), BluetoothManager.shared.connectState.filter{ $0 == .connected }.mapToVoid())
            .merge()
            .map { _ in
                var items: [HomeActionItem] = []
                
                items.append(.headItem(ViewModel: HomeHeadCellModel()))
                items.append(.equalizerItem(viewModel: HomeEqualizerCellViewModel()))
                items.append(.settingItem(viewModel: HomeSettingCellModel()))
                
                //items.append(.spatialAudioSectionItem)
                //items.append(.spatialAudioItem(viewModel: HomeSpatialAudioCellModel(type: .music)))
                //items.append(.spatialAudioItem(viewModel: HomeSpatialAudioCellModel(type: .movie)))
                //items.append(.spatialAudioItem(viewModel: HomeSpatialAudioCellModel(type: .game)))
                
                return items
            }
        return Output(items: dataSource)
    }
    
}
